unit MySqlQueryEx;

interface

uses
  SysUtils,
  DB,
  mySQLDbTables, CodeSiteLogging ;

Type
  TMySqlQueryEx = class
    private
      FDB:    TmySQLDatabase;
      FQuery: TmySQLQuery;
    protected
    public
      property Query: TMySqlQuery read FQuery Write FQuery;

      function NewQuery: TMysqlQuery;
      Function GetGameTitle(aGID:String):String;
      Function Execute: Boolean;
      Function Open: Boolean;
      constructor Create(aMDB:TMysqlDatabase); reintroduce;
      Destructor  Destroy; override;
  end;

implementation

{ TMysqlUtils }

constructor TMySqlQueryEx.Create(aMDB: TMysqlDatabase);
begin
  FDB := aMDB;
  FQuery := TmySQLQuery.Create(nil);
  FQuery.Database := FDB;
end;

destructor TMySqlQueryEx.Destroy;
begin
  FQuery.Free;
  inherited;
end;

function TMySqlQueryEx.Execute: Boolean;
begin
  Result := False;
  Try
    FQuery.ExecSQL;
    Result := True;
  Except
  end;
end;

function TMySqlQueryEx.Open: Boolean;
begin
  Result := False;
  Try
    FQuery.Open;
    Result := True;
  Except on e:Exception do
    begin
      Codesite.SendError('MySqlOPen Error:%s, %s',[ e.Message, FQuery.Sql.text ]);
    end;
  end;
end;


function TMySqlQueryEx.GetGameTitle(aGID: String): String;
begin
  Result := '';

  FQuery.Close;

  with FQuery do begin
    SQL.Clear;
    sql.add('select title from c_game where mgid = :mgid');
    parambyName('mgid').AsString := aGID;
    try
      open;
      if not FQuery.IsEmpty then Result := FieldByName('title').AsString;
      FQuery.Close;
    except
      Exit;
    end;
  end;

end;


function TMySqlQueryEx.NewQuery: TMysqlQuery;
begin
  Result  := TmySQLQuery.Create(nil);
  Result.Database := FDB;
end;

end.
